const jwt = require('jsonwebtoken');
const { configFile:{ token: { sign }}} = require('../config/readYamlFile');
const Token = {
    encrypt: function (data,time) {
        return jwt.sign(data,sign,{ expiresIn: time})
    },
    decrypt: function (token) {
        try{
            const data = jwt.verify(token,sign)
            return {
                token: true,
                id: data.id
            }
        }catch (e) {
            return {
                token: false,
                data: e
            }
        }
    }
}

module.exports = Token